<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        //代理的对象
        const obj = {
            a: 1,
            b: 2
        }
        const proxy = new Proxy(obj, {
            //重写set方法
            set(target, propertyKey, value) {
                console.log('哈哈哈，我居然被运行了');
                Reflect.set(target, propertyKey, value)
            },
            //重写get方法
            get(target, propertyKey) {
                if (Reflect.has(target, propertyKey)) {
                    return Reflect.get(target, propertyKey)
                } else {
                    return -1
                }
            },
            //重写has方法
            has(target, propertyKey) {
                return Reflect.has(target, propertyKey)
            }
        })

        proxy.c = 3
        console.log(proxy.d);
        console.log('a' in proxy);
        console.log('d' in proxy);

    </script>
</body>

</html>